package com.yanqu.road.server.cmd.activity.unionwar;

import com.yanqu.road.entity.enums.eUnionPosition;
import com.yanqu.road.entity.union.activitygroup.UnionActivityGroupUnion;
import com.yanqu.road.entity.union.activitygroup.UnionActivityGroupUser;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.unionwar.CrossUnionWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.union.GameUnionActivityGroupMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_UNION_WAR_IS_COMMANDER, desc = "是否是指挥官")
public class UnionWarIsCommanderCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        CrossUnionWarProto.CrossUnionWarIsCommanderReqMsg reqMsg = CrossUnionWarProto.CrossUnionWarIsCommanderReqMsg.parseFrom(packet.getBytes());
        UnionActivityGroupUnion unionData = GameUnionActivityGroupMgr.getUnionData(reqMsg.getActivityId(), player.getUserId());
        if(unionData == null){
            ret = GameErrorCode.E_UNION_ACTIVITY_GROUP_NO_ABLE;
            return;
        }
//        if(user.getPosition() == eUnionPosition.Master.getValue()){
//            player.sendPacket(Protocol.U_UNION_WAR_IS_COMMANDER, CrossUnionWarProto.CrossUnionWarIsCommanderRespMsg.newBuilder().setRet(true));
//            return;
//        }
        player.sendUnionActivityGroupPacket(Protocol.C_UNION_WAR_IS_COMMANDER, reqMsg.toBuilder(), unionData.getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_UNION_WAR_IS_COMMANDER, CrossUnionWarProto.CrossUnionWarIsCommanderRespMsg.newBuilder().setRet(ret));
        }
    }
}
